<?php

namespace common\models\course;

use Yii;

/**
 * This is the model class for table "{{%course_group_users}}".
 *
 * @property int $id
 * @property string $group_id 群ID
 * @property int $user_id 用户ID
 * @property int $role_id 用户身份
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class CourseGroupUsers extends \common\base\ActiveRecord {

    use \common\traits\Constants;
    use \common\traits\TimestampBehavior;
    use \common\traits\QueryInstanceActiveRecord;

    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%course_group_users}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['group_id'], 'required'],
            [['user_id', 'role_id', 'group_id', 'status', 'created_at', 'updated_at'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'group_id' => '群ID',
            'user_id' => '用户ID',
            'role_id' => '用户身份',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    public function getGroup() {
        return $this->hasOne(CourseGroup::className(), ['id' => 'group_id']);
    }

    public function getRole() {
        return $this->hasOne(\common\models\teacher\TeacherRole::className(), ['id' => 'role_id']);
    }

    public function getUser() {
        return $this->hasOne(\common\models\user\UserMeta::className(), ['id' => 'user_id']);
    }

}
